package com.itheima.Jiuye14;

import java.util.concurrent.Semaphore;

public class MyRunnable implements Runnable{
    Semaphore semaphore = new Semaphore(2);  //创建限流对象，参数为最大通行数，（注意：不是每次一定是这么多个通行，而是最多这么多个同时通行）

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println("获取到通行证，开始行驶");
            Thread.sleep(1000);
            System.out.println("归还通行证");
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
